<h1>Мэдээ</h1>

<?php echo link_to('жагсаалт', 'content/index', array('class'=>'title'))?> 
<span class="separator"> | </span>
<?php echo link_to('шинээр нэмэх', 'content/new', array('class'=>'title'))?>
<br clear="all">
<br clear="all">

<form action="<?php echo url_for('content/index')?>" method="GET">
  <b>Хайх үг:</b>&nbsp;
  <input id="keyword" name="keyword" value="<?php echo $sf_request->getParameter('keyword')?>" style="width:400px;"/>
  <input type="submit" value="Submit" style="cursor:pointer;font-weight:bold;" />
</form>

<table width="100%">
  <thead>
    <tr>
      <th>#</th>
      <th>Image</th>
      <th>News</th>
      <th>Category</th>
      <th>Sort</th>
      <th>Created At</th>
      <th>#</th>
    </tr>
  </thead>
  <tbody>
    <?php $i=0; foreach ($pager->getResults() as $content): ?>
    <tr style="<?php if($content->getIsFeatured()) echo 'background-color:#ffffaa;'?>">
      <td><?php echo ++$i?></td>            
      <td><?php echo image_tag('/uploads/news/'.$content->getImage(100), array('style'=>'max-height:150px;max-width:200px;')) ?></td>
      <td><b><?php echo $content ?></b><hr/>
          <?php echo myTools::utf8_substr(strip_tags($content->getIntro()), 0, 150).' ...' ?><hr/>
          <?php echo myTools::utf8_substr(strip_tags($content->getContent()), 0, 150).' ...' ?>
      </td>
      <td nowrap>
        <?php echo $content->getBbSeason() ? '<b>Улирал</b>: '.$content->getBbSeason().'<br/>' : ''?>
        <?php echo $content->getObjectType() ? '<b>Төрөл</b>: '.$content->getObjectType().' (<b><em>'.$content->getObject().'</em><b>)<br/>' : ''?>
        <?php echo $content->getCategory() ? '<b>Category</b>: '.$content->getCategory() : ''?>
      </td>
      <td><?php echo $content->getSort() ?></td>
      <td><?php echo $content->getCreatedAt() ?></td>
      <td nowrap>
        <?php if($content->getIsFeatured()==1):?>
          <a href="<?php echo url_for('content/featured?id='.$content->getId().'&status=0') ?>">Онцлох биш болгох</a><br><br>
        <?php else:?>
          <a href="<?php echo url_for('content/featured?id='.$content->getId().'&status=1') ?>">Онцлох болгох</a><br><br>
        <?php endif;?>
        <a href="<?php echo url_for('content/edit?id='.$content->getId()) ?>">Засварлах</a><br><br>
        <a onclick="return confirm('Та итгэлтэй байна уу?')" href="<?php echo url_for('content/delete?id='.$content->getId()) ?>">Устгах</a>
      </td>
    </tr>
    <?php endforeach; ?>
  </tbody>
</table>
<?php echo pager($pager, 'content/index')?>


<script type="text/javascript">
function loadObjects()
{
  $.ajax({
      url: "<?php echo url_for('content/loadObjects')?>",
      data: {objectType : $('#objectType').val(), objectId: <?php echo $sf_request->getParameter('objectId') ? $sf_request->getParameter('objectId') : 0?>},
      type: "POST",
      success: function(data){
          $('#container_object_id').html('<select id="objectId" name="objectId" style="width:400px;">' + data + '</select>');
      }
  });
  return false;
}

$(document).ready(function() {
    loadObjects();  
});
</script>